//
//  nearByViewController.m
//  INAlienLand
//
//  Created by dllo on 15/7/3.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "nearByViewController.h"
#import "nearCollectionViewCell.h"
#import "nearmodel.h"
#import "nearTypeCollectionViewCell.h"


#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface nearByViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UIScrollViewDelegate>
@property (nonatomic,retain)UITableView *nearTableView;
@property (nonatomic,retain)UICollectionView *nearCollection;
@property (nonatomic,retain)UICollectionView *nearCollectiondetile;
@property (nonatomic,retain)UIScrollView *transcontroller;
@property (nonatomic,assign)NSInteger I;

@end

@implementation nearByViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"我的附近";

    //创建俩个collectionview
    [self createNearcollect];
    
}

-(void)createNearcollect
{
    //定义一个flowlayout
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
//    flowLayout设置大小
    flowLayout.itemSize =CGSizeMake(80, 50);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 0;
    self.nearCollection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 50) collectionViewLayout:flowLayout];
    [self.view addSubview:self.nearCollection];
    self.nearCollection.delegate = self;
    self.nearCollection.dataSource = self;
    self.nearCollection.pagingEnabled = YES;

    
    //定义一个flowlayout
    UICollectionViewFlowLayout *flowLayoutdetile = [[UICollectionViewFlowLayout alloc]init];
    flowLayoutdetile.itemSize =CGSizeMake( WIDTH, HEIGHT-50-64-49);
//    flowLayout设置方向
    flowLayoutdetile.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayoutdetile.minimumLineSpacing = 0;
    flowLayoutdetile.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    self.nearCollectiondetile = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 50, WIDTH, HEIGHT-50-64-49) collectionViewLayout:flowLayoutdetile];
    [self.view addSubview:self.nearCollectiondetile];
    self.nearCollectiondetile.delegate = self;
    self.nearCollectiondetile.dataSource = self;
    
    
    [self.nearCollectiondetile registerClass:[nearCollectionViewCell class] forCellWithReuseIdentifier:@"nearReused"];
    [self.nearCollection registerClass:[nearTypeCollectionViewCell class] forCellWithReuseIdentifier:@"nearReuse"];
    self.nearCollectiondetile.pagingEnabled = YES;
    
    
    
    
}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([collectionView isEqual:self.nearCollection]) {
        nearTypeCollectionViewCell *nearcell=[collectionView dequeueReusableCellWithReuseIdentifier:@"nearReuse" forIndexPath:indexPath];
        nearcell.backgroundColor = [UIColor whiteColor];
        if (indexPath.row==0) {
            nearcell.typeLable.text =@"全部";
        }else if (indexPath.row==1) {
            nearcell.typeLable.text =@"景点";
        }else if (indexPath.row==2) {
            nearcell.typeLable.text =@"住宿";
        }else if (indexPath.row==3) {
            nearcell.typeLable.text =@"餐厅";
        }else if (indexPath.row==4) {
            nearcell.typeLable.text =@"休闲娱乐";
        }else
        {
            nearcell.typeLable.text =@"购物";
        }
        
        
        return nearcell;
    }else {
        nearCollectionViewCell *nearcell1=[collectionView dequeueReusableCellWithReuseIdentifier:@"nearReused" forIndexPath:indexPath];
        
        [self.nearCollection scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
//       UICollectionViewCell *cell =[self.nearCollection cellForItemAtIndexPath:indexPath];
//        [cell setBackgroundColor:[UIColor redColor]];
        
        if (indexPath.row==0) {
            nearcell1.str = @"0";
        }else  if (indexPath.row==1) {
            nearcell1.str = @"11";
        }else  if (indexPath.row==2) {
            nearcell1.str = @"10";
        }else  if (indexPath.row==3) {
            nearcell1.str = @"5";
        }else  if (indexPath.row==4) {
            nearcell1.str = @"21";
        }else
        {
           nearcell1.str = @"6";
        }
        return nearcell1;
    }
    
   
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([collectionView isEqual:self.nearCollection]) {
        [self.nearCollectiondetile scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
   }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
